#ifndef LEETCODE_CN_CPP_PROBLEMS_152_H
#define LEETCODE_CN_CPP_PROBLEMS_152_H

#include <vector>

using namespace std;

namespace problem_152
{

class Solution
{
public:
    int maxProduct(vector<int> &nums)
    {
        int minProd = nums.front(), maxProd = nums.front();
        int result = maxProd;
        for (int i = 1; i < nums.size(); ++i)
        {
            int _min = min(minProd * nums[i], maxProd * nums[i]);
            int _max = max(minProd * nums[i], maxProd * nums[i]);
            minProd = min(_min, nums[i]);
            maxProd = max(_max, nums[i]);
            result = max(result, maxProd);
        }
        return result;
    }
};

} // namespace problem_152

#endif //LEETCODE_CN_CPP_PROBLEMS_152_H
